
import { createSlice } from "@reduxjs/toolkit";

export const countStore = createSlice({
    name:'count',
    initialState:{
        count:0
    },
    reducers:{
        increment(state){
            state.count++
        },
        decrement(state){
            state.count--
        },
        addToNum(state,action){
            state.count +=action.payload
        }
    }
})

// 解构出来actionCreators函数
const {increment, decrement, addToNum} = countStore.actions

// 获取reducer
const reducer = countStore.reducer;
// 以按需导出的方式导出actionCreator
export {increment, decrement, addToNum}
// 以默认导出的方式导出reducer
export default reducer